<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class Tag extends Model implements Sortable
{
    use HasFactory;
    use SortableTrait;

    public $timestamps = null;
    protected $fillable = [
        'name',
        'order'
    ];

    protected $sortable = [
        // 设置排序字段名称
        'order_column_name' => 'order',
        // 是否在创建时自动排序，此参数建议设置为true
        'sort_when_creating' => true,
    ];

    public function clues() {
        return $this->hasMany(Clue::class, 'tag_id' , 'id');
    }

    public static function toOptions() {
        return static::query()->orderBy('order')->pluck('name' , 'id')->toArray();
    }

}
